package com.wit.health.UI;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;

import com.wit.health.R;
import com.wit.health.adapter.ExerciseAdapter;
import com.wit.health.decorator.SpacesItemDecoration;
import com.wit.health.pojo.Action;

import java.util.ArrayList;
import java.util.List;

public class ExerciseActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_exercise);
        // 初始化运动数据
        List<Action> exerciseList = new ArrayList<>();
        exerciseList.add(new Action("中风康复", R.drawable.squat_image,"中风康复示例视频，科学运动，逐步恢复生活自理能力。",R.raw.poststroke ));
        exerciseList.add(new Action("平板支撑", R.drawable.plank_image,"video_url_2", "运动2的简介"));
        exerciseList.add(new Action("仰卧起坐", R.drawable.situp_image,"video_url_3", "运动3的简介"));
        exerciseList.add(new Action("俯卧撑", R.drawable.pushup_image,"video_url_4", "运动4的简介"));
        exerciseList.add(new Action("开合跳", R.drawable.jack_image,"video_url_5", "运动5的简介"));
        exerciseList.add(new Action("慢跑", R.drawable.jogging_image,"video_url_6", "运动6的简介"));
        exerciseList.add(new Action("开合跳", R.drawable.cycling_image,"video_url_7", "运动7的简介"));
        // ... 添加更多运动数据

        // 设置 RecyclerView
        RecyclerView recyclerView = findViewById(R.id.exerciseRecyclerView);
        recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
        ExerciseAdapter adapter = new ExerciseAdapter(exerciseList);

        // 设置点击事件监听器
        adapter.setOnItemClickListener(new ExerciseAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(Action exercise) {
                // 处理运动项的点击事件,例如跳转到详情页面
                Intent intent = new Intent(ExerciseActivity.this, ExerciseDetailActivity.class);
                intent.putExtra("exerciseName", exercise.getName());
                intent.putExtra("exerciseVideoUrl", exercise.getVideoUrl());
                intent.putExtra("exerciseVideoResourceId", exercise.getVideoResourceId());
                intent.putExtra("exerciseDescription", exercise.getDescription());
                startActivity(intent);
            }
        });

        recyclerView.setAdapter(adapter);
        // 添加 ItemDecoration
        int spacingInPixels = getResources().getDimensionPixelSize(R.dimen.item_spacing); // 从资源文件中获取间距值
        recyclerView.addItemDecoration(new SpacesItemDecoration(spacingInPixels));
    }



}